package com.bestv.database.dao;

import com.bestv.database.vo.IncrSeries;
import com.bestv.utils.database.DBConnectionManager;
import com.bestv.utils.database.JDBCHelper;

import java.sql.Connection;
import java.util.List;

/**
 * Created by Henry on 14-7-10.
 */
public class IncrSeriesDao {
    public void truncate() {
        Connection conn = DBConnectionManager.getMasterConnection();
        String sql = "TRUNCATE incr_series";
        JDBCHelper.executeUpdate(conn, sql);
    }

    public void saveBatch(List<IncrSeries> serieses) {
        Object[][] matrix = new Object[serieses.size()][16];
        for (int i=0; i<serieses.size(); i++) {
            IncrSeries series = serieses.get(i);
            Object[] array = new Object[16];
            array[0] = series.getMediaCode();
            array[1] = series.getName();
            array[2] = series.getType();
            array[3] = series.getGenre();
            array[4] = series.getTags();
            array[5] = series.getKeywords();
            array[6] = series.getActors();
            array[7] = series.getDirector();
            array[8] = series.getSourceType();
            array[9] = series.getRegion();
            array[10] = series.getLanguage();
            array[11] = series.getVolumnCount();
            array[12] = series.getReleaseYear();
            array[13] = series.getAddedTime();
            array[14] = series.getStatus();
            array[15] = series.getPrice();
            matrix[i] = array;
        }
        Connection conn = DBConnectionManager.getMasterConnection();
        String sql = "INSERT INTO incr_series (MediaCode, Name, Type, Genre, Tags, Keywords, Actors, Director, SourceType, Region, Language, VolumnCount, ReleaseYear, AddedTime, Status, Price) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        JDBCHelper.executeBatch(conn, sql, matrix);
    }
}
